#include "library/base/guid.h"

namespace Base
{
	Guid::Guid(const GUID& value)
	{
		memcpy(&value_, &value, sizeof(GUID));
	}

	Guid::Guid(const Guid& guid)
	{
		memcpy(&value_, &guid.value_, sizeof(GUID));
	}

	Guid& Guid::operator=(const Guid& guid)
	{
		memcpy(&value_, &guid.value_, sizeof(GUID));
		return *this;
	}

	GUID Guid::GetValue() const
	{
		return value_;
	}

	WString Guid::ToWString() const
	{
		WCHAR str[100] = {0};
		if (StringFromGUID2(value_, str, 100) == 0)
			throw "failed to convert guid to string";
		return WString(str);
	}

	// static
	Guid Guid::NewGuid()
	{
		GUID value;
		if (CoCreateGuid(&value) != S_OK)
			throw "";
		return Guid(value);
	}
}